package top.lcm889.oj.leetcodeTop200;

/**
 * @link https://leetcode-cn.com/problems/power-of-two/submissions/
 * @author Coder-lcm
 * @date 2021/4/10
 */
public class LC231_2的幂 {
    // 1.位运算
    public static boolean isPowerOfTwo(int n) {

        if (n == 1) return true;
        if (n == 2) return true;
        int i = 1;
        while (true){
            int tmp = 2 << i;
            if (tmp < 0) {
                break;
            }
            if (tmp < n) {
                i++;
                continue;
            }else if (tmp == n) {
                return true;
            }else {
               break;
            }
        }
        return false;
    }
    // leetcode大招
    public static boolean isPowerOfTwo2(int n) {
        if(n == 0) return false;
        long x = (long) n;
        return (x & (-x)) == x;
    }

    public static void main(String[] args) {
        int a = 15;
//        System.out.println(2 << 30);
        System.out.println(isPowerOfTwo2(1073741824));
        System.out.println(3 & (3));

        System.out.println("位运算++++++++++=");
        System.out.println(~2);
    }
}
